//
//  LZManageReviewsBGScrollView.m
//  laziz_Merchant
//
//  Created by xbn_iMac on 2016/12/18.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZManageReviewsBGScrollView.h"
#import "UIScrollView+LZContentOffset.h"
#import "LZManageReviewsVideosTableView.h"
#import "LZManageReviewsRestaurantReviewsTableView.h"
#import "Masonry.h"

@interface LZManageReviewsBGScrollView ()<UIScrollViewDelegate>

@property (nonatomic ,assign) NSInteger selectedButtonTag;

@end

@implementation LZManageReviewsBGScrollView

- (instancetype) initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.contentSize=CGSizeMake(SCREEN_WIDTH*2, 0);
        self.delegate=self;
        self.showsHorizontalScrollIndicator=NO;
        self.pagingEnabled=YES;
        self.scrollEnabled = NO;
        self.bounces=NO;
        [self configSubTableViews];
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    [self setLanguageContentOffset];
}

#pragma mark - configUI

- (void)configSubTableViews {
    UIView *container = [[UIView alloc] init];
    [self addSubview:container];
    
    [container mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
        make.height.equalTo(self);
    }];
    
    [container addSubview:self.videoTable];
    [container addSubview:self.restaurantsReviewTable];
    
    [self.videoTable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.and.bottom.equalTo(container);
        make.leading.mas_equalTo(0);
        make.width.mas_equalTo(SCREEN_WIDTH);
    }];
    
    [self.restaurantsReviewTable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.and.bottom.equalTo(container);
        make.leading.equalTo(self.videoTable.mas_trailing);
        make.width.mas_equalTo(SCREEN_WIDTH);
    }];
    
    [container mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self.restaurantsReviewTable.mas_trailing);
    }];
}

#pragma mark - 懒加载

// 视频列表
- (LZManageReviewsVideosTableView*)videoTable {
    if (_videoTable) {
        return _videoTable;
    }
    
    LZManageReviewsVideosTableView *table = [[LZManageReviewsVideosTableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    table.tag = 10;
    _videoTable = table;
    return _videoTable;
}

// 餐厅的评论列表
- (LZManageReviewsRestaurantReviewsTableView*)restaurantsReviewTable {
    if (_restaurantsReviewTable) {
        return _restaurantsReviewTable;
    }
    
    LZManageReviewsRestaurantReviewsTableView *table = [[LZManageReviewsRestaurantReviewsTableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    table.tag = 11;
    _restaurantsReviewTable = table;
    return _restaurantsReviewTable;
}

#pragma mark - Public Method

- (void)clickButtonTag:(NSInteger)tag {
    self.selectedButtonTag = tag;
    LZHorizontalBaseSubTableView *table = [self viewWithTag:tag+10];
    [table checkHaveData];
    [self setContentOffset:CGPointMake(table.frame.origin.x, 0)];
    
}

@end
